package com.lc.stock.module.filtrate.filter.impl;

import cn.hutool.core.collection.CollUtil;
import com.lc.stock.common.Constant;
import com.lc.stock.module.filtrate.filter.FiltrateStockFilter;
import com.lc.stock.module.compyindustryconcept.dao.CompyIndustryConceptDao;
import com.lc.stock.module.compyindustryconcept.domain.CompyIndustryConcept;
import com.lc.stock.module.compyindustryconcept.domain.IndustryConcept;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lichen
 * @description 筛选出非房地产板块的股票
 * @menu
 * @date 2023/2/6 13:39
 */
@Slf4j
@Component
public class PropertyCompanyFilter implements FiltrateStockFilter {

    @Autowired
    private CompyIndustryConceptDao compyIndustryConceptDao;

    @Override
    public boolean doFilter(String stockCode) {
        CompyIndustryConcept byStockCode = compyIndustryConceptDao.findByStockCode(stockCode);
        if(null == byStockCode){
            return true;
        }
        List<IndustryConcept> industryConcepts = byStockCode.getIndustryConcepts();
        if(CollUtil.isNotEmpty(industryConcepts)){
            //根据公司相关指数、行业、概念，判断是否房地产公司
            boolean present = industryConcepts.stream().filter(item -> item.getCode().equals(Constant.PROPERTY_COMPY)).findFirst().isPresent();
            if(present) return false;
        }
        return true;
    }

    @Override
    public String getErrorMsg() {
        return "公司是房地产公司;";
    }
}
